package cn.itcast.service.company.impl;

import cn.itcast.dao.company.CompanyDao;
import cn.itcast.domain.company.Company;
import cn.itcast.service.company.CompanyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CompanyServiceImpl implements CompanyService {
    @Autowired
    private CompanyDao companyDao;

    @Override
    public List<Company> findAll() {
        return companyDao.findAll();
    }

    @Override
    public void deleteCompanyById(String id) {
        companyDao.deleteCompanyById(id);

    }

    @Override
    public void save(Company company) {
        companyDao.save(company);

    }

    @Override
    public void updateCompany(Company company) {
        companyDao.updateCompany(company);

    }

    @Override
    public Company findCompanyById(String id) {
       return companyDao.findCompanyById(id);
    }

    @Override
    public PageInfo pageHelperFindAll(int pageNum, int pageSize) {
        //1、调用静态方法
        PageHelper.startPage(pageNum, pageSize);
        //2、紧跟着的查询方法自动分页
       List<Company> list = companyDao.pageHelperFindAll();
       //3、封装数据到pageBean（pageInfo）
        PageInfo pageInfo = new PageInfo(list);
        //4、返回pageInfo
        return pageInfo;
    }


}
